<?php

/**
 * simple_image - Simple image object
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Std_ImageObject extends Erra_Fields_Base_Object {

    function __construct($objectId, $buildArgs = null) {
        parent::__construct($objectId, $buildArgs);

        $image_content = Erra_Fields_Image::create('image_content')
                ->setDescription(__('Image content'));
        if (strlen($buildArgs)) {
            $buildArgs = explode('x', $buildArgs);
            if (is_array($buildArgs) && count($buildArgs) == 2) {
                $image_content->setWidth(trim($buildArgs[0]));
                $image_content->setheight(trim($buildArgs[1]));
            }
        }

        $alt_text = Erra_Fields_Text::create('alt_text')->setDescription(__('Alt text'));

        $this->addFields($image_content, $alt_text);
    }

    public function __render($displayArgs = null) {
        $res = '';
        if (strlen($this->image_content->value)) {
            $res = '<img ' . $this->getHtmlAttributes() . ' alt="' . $this->alt_text->value . '" src="' . config_get('path.public_upload_directory') . '/' . $this->image_content->value . '" ' . $displayArgs . ' />';
        }
        return $res;
    }

}

?>